package com.powernode.controller;

import com.powernode.model.Result;
import com.powernode.service.AliyunSmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @create: 2024/7/24
 * @author: gyhe10
 * @description: 短信业务控制层
 **/

@Api(tags = "短信业务接口管理")
@RestController
@RequestMapping("p/sms")
public class AliyunSmsController {

    @Resource
    private AliyunSmsService aliyunSmsService;

    /**
     * 发送短信验证码
     * @param map 手机号码
     * @return
     */
    @ApiOperation("发送短信验证码")
    @PostMapping("send")
    public Result<String> sendPhoneCode(@RequestBody Map<String, Object> map) {
        aliyunSmsService.sendPhoneCode(map);
        return Result.success("短信发送成功");
    }

    /**
     * 绑定会员手机号
     * @param map 手机号码和验证码
     * @return
     */
    @ApiOperation("绑定用户手机号")
    @PostMapping("savePhone")
    public Result<String> info(@RequestBody Map<String, String> map) {
        Boolean saved = aliyunSmsService.savePhone(map);
        return Result.handle(saved);
    }
}
